package com.paas.form.core.element.constants;

public class TreeConstant {

    public static final String VM_TREE_HTML = "<div class=\"h100 tree-left\">\n" +
            "                <div class=\"tree-title\">\n" +
            "                    已选：{{ tree.selectNode.${treePropsLabel} ? tree.selectNode.${treePropsLabel} : \"请选择\" }}\n" +
            "                </div>\n" +
            "                <div class=\"tree-box\">\n" +
            "                    <el-tree :data=\"tree.data\" :props=\"tree.defaultProps\" node-key=\"${treePropsValue}\"  lazy :load=\"loadNode\" highlight-current :check-strictly=\"true\"  @node-click=\"handleTreeNodeClick\">\n" +
//            "                        <span class=\"custom-tree-node\" slot-scope=\"{ node }\">\n" +
//            "                            <span><i :class=\"nodeIconConfig(node)\"></i> {{ node.label }}</span>\n" +
//            "                        </span>\n" +
            "                    </el-tree>\n" +
            "                </div>\n" +
            "            </div>";

    public static final String VM_TREE_JS_DATA = "tree: {\n" +
            "                    data: [],\n" +
            "                    selectNode: { groupOrNot: true },\n" +
            "                    defaultProps: {\n" +
            "                        label: \"${treePropsLabel}\",\n" +
            "                        children: \"children\",\n" +
            "                        isLeaf: (data) => {\n" +
            "                            return data.isLast !== \"0\" ? false : true;\n" +
            "                        },\n" +
            "                    },\n" +
            "                },";


    public static final String VM_TREE_JS_METHODS = "/**\n" +
            "             * 图标设置\n" +
            "             * @param {*} node\n" +
            "             */\n" +
            "            nodeIconConfig(node) {\n" +
            "                var data = node.data\n" +
            "                if (data.type === '1') {\n" +
            "                    return node.expanded ? 'el-icon-folder-opened' : 'el-icon-folder'\n" +
            "                } else {\n" +
            "                    return 'el-icon-tickets'\n" +
            "                }\n" +
            "            },\n" +
            "\n" +
            "            /**\n" +
            "             * 选择分组-回调\n" +
            "             * @param {*} item\n" +
            "             */\n" +
            "            handleTreeNodeClick(item) {\n" +
            "                this.tree.selectNode = item;\n" +
            "                this.searchForm[\"parentId\"] = item[\"${treePropsValue}\"];\n" +
            "                this.getDataList();\n" +
            "            },\n" +
            "\n" +
            "            /**\n" +
            "             * 加载节点\n" +
            "             */\n" +
            "            loadNode(node, resolve) {\n" +
            "                // 如果展开第一级节点，从后台加载一级节点列表\n" +
            "                if (node.level == 0) {\n" +
            "                    this.getGroup(resolve);\n" +
            "                }\n" +
            "                // 如果展开其他级节点，动态从后台加载下一级节点列表\n" +
            "                if (${treeLazyType} === 1 && node.level >= 1) {\n" +
            "                    this.getChildDataList(node, resolve);\n" +
            "                }else {\n" +
            "                    resolve([]);\n" +
            "                }" +
            "            },\n" +
            "\n" +
            "            /**\n" +
            "             * 获取分组信息\n" +
            "             */\n" +
            "            getGroup() {\n" +
            "                try {\n" +
            "                    const params = {status: 1, levels: \"0\",};\n" +
            "                    ${className}Service.queryList(params).then(({ data }) => {\n" +
            "                        if (data && data.length > 0) {\n" +
            "                            this.tree.data = data;\n" +
            "                        }\n" +
            "                    });\n" +
            "\n" +
            "                } catch (e) {\n" +
            "                    this.$message({ showClose: true, message: \"加载失败，错误：\" + e.message, type: \"error\" });\n" +
            "                }\n" +
            "            },\n" +
            "\n" +
            "            getChildDataList(node, resolve){\n" +
            "                const params = { status: 1, parentId: node.data.${treePropsValue} };\n" +
            "                ${className}Service.queryList(params).then(({ data }) => {\n" +
            "                    if (data && data.length > 0) {\n" +
            "                        resolve(data);\n" +
            "                    }\n" +
            "                });\n" +
            "\n" +
            "            },";

}
